﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 剪刀石头布游戏
{
    class Judger
    {
        static ComputerPlayer computer = new ComputerPlayer();
        static UserPlayer user = new UserPlayer();
        public bool statr(String inputName, String computName)
        {
            int comWinCount = 0;
            int userWinCount = 0;
            bool flag = false;
            int count = 1;
            string j;
            Console.WriteLine("准备开始游戏了吗(y/n)");
            j = Console.ReadLine();
            if (j.Equals("y"))
            {
               m: do
                {
                    count++;
                    //玩家出拳
                    int userValue = user.getInputValue();
                    Console.WriteLine(inputName + "出拳： ");
                    //电脑出拳
                    int comValue = computer.getInputValue();
                    Console.WriteLine(computName + "出拳： " );
                    //裁判比较
                    int result = compare(comValue, userValue);
                    if (result == 1)
                    {
                        Console.WriteLine("笨蛋," + computName + "赢了");
                        comWinCount++;
                    }
                    else if (result == -1)
                    {
                        Console.WriteLine("笨蛋," + inputName + "赢了");
                        userWinCount++;
                    }
                    else
                    {
                        Console.WriteLine("嘿嘿，和局真衰，等着瞧吧");
                    }
                    Console.WriteLine("准备开始游戏了吗(y/n)");
                    j = Console.ReadLine();
                    switch (j)
                    {
                        case "y":
                            flag = true;
                            break;
                        case "n":
                            Console.WriteLine("==========================================");
                            Console.WriteLine(inputName  + " VS "+ computName);
                            Console.WriteLine("对战次数" + count);
                            Console.WriteLine();
                            Console.WriteLine("姓名\t\t得分");
                            Console.WriteLine(inputName+"\t\t" + userWinCount);
                            Console.WriteLine(computName + "\t\t" + comWinCount);
                            if (userWinCount> comWinCount)
                            {
                                Console.WriteLine(inputName+"赢");
                            }
                            else if (userWinCount > comWinCount)
                            {
                                Console.WriteLine(computName+"赢");
                            }
                            else
                            {
                                Console.WriteLine("平局");
                            }
                            Console.WriteLine("退出系统");
                            break;
                    }
                    goto m;
                } while (flag);
            }
            else if (j.Equals("n"))
            {
                Console.WriteLine("系统退出");
            }
            return flag;
        }
        public int compare(int computerValue, int userValue)
        {
            if (computerValue == userValue)
            {
                return 0;
            }
            else if (computerValue == 1)//1 剪刀
            {
                if (userValue == 2)//1 石头
                {
                    return -1;
                }
                else//3 布
                {
                    return 1;
                }
            }
            else if (computerValue == 2)//2 石头
            {
                if (userValue == 1)// 1 剪刀
                {
                    return 1;
                }
                else//3 布
                {
                    return -1;
                }
            }
            else//3 computerValue==布
            {
                if (userValue == 2)//石头
                {
                    return 1;
                }
                else// 1 剪刀
                {
                    return -1;
                }
            }
        }
    }
}
